//package cn.school.servlet;
//
//import cn.school.entity.Admin;
//import cn.school.service.AdminService;
//
//import javax.servlet.ServletException;
//import javax.servlet.annotation.WebServlet;
//import javax.servlet.http.*;
//import java.io.IOException;
//import java.net.URLEncoder;
//
//@WebServlet( "/loginServlet")
//public class LoginServletold extends HttpServlet {
//
//    private int   checkCookies(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//        Cookie[] cookies = request.getCookies();
//        //假设统计登录次数的叫cfnum
//        Cookie visit=null;
//        for(int i=0;cookies!=null && i<cookies.length;i++){
//            if(cookies[i].getName().equals("cfnum")){
//                visit=cookies[i];
//                break;
//            }
//        }
//        if(visit==null){
//            //首次登录
//            visit=new Cookie("cfnum","0");
//        }
//        int num=Integer.parseInt(visit.getValue());
//        num++;//数量+1
//        visit.setValue(String.valueOf(num));
//        visit.setMaxAge(86400);//1天
//        response.addCookie(visit);//必须要再次发到响应中，因为cookie是存在浏览器端的
//        return num;
//    }
//
//    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//        //登录之前判断
//        int num=this.checkCookies(request,response);
//        if(num>3){
//            response.setContentType("text/html;charset=utf-8");
//            response.getWriter().print("您今天登录次数太多，请一天后再试");
//            return;
//        }
//        request.setCharacterEncoding("utf-8");
//        String name=request.getParameter("userName");///request.getParameterValues("userName")[0];
//        String pass=request.getParameter("userPass");
//        Admin login = AdminService.INST.login(name, pass);
//        if(login!=null){
//             //用户的信息放入session
//            HttpSession session = request.getSession();//获得会活对象
//            session.setAttribute("USER_LOGIN",login);
//            //把用户名存入cookie
//            Cookie c=new Cookie("loginname",name);
//            c.setMaxAge(3600*24*7);//活多久
//            response.addCookie(c);//@!!!!!
//            response.sendRedirect("main.jsp");
//            return;
//        }
//
//        request.setAttribute("msg","错误的用户名或者密码！");
//        request.getRequestDispatcher("/login.jsp").forward(request,response);
//    }
//
//    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//
//    }
//}
